package com.campus.dao;

import com.campus.dao.provider.UnitInfoDynSqlProvider;
import com.campus.pojo.ProParamInfo;
import com.campus.pojo.ProUnitInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface UnintDao {
    @SelectProvider(type = UnitInfoDynSqlProvider.class,method = "selectByPage")
    List<ProUnitInfo> selectByPage(Map<String,Object> params);    //分页查询

    @SelectProvider(type = UnitInfoDynSqlProvider.class,method = "count")
    int count(Map<String,Object> params);//返回满足条件的记录个数

    @Select("select id,name from pro_paraminfo where delState = 1 and areaId = #{areaId}")
    List<ProParamInfo> selectAllType(String areaId); //查找所有类型

    @Insert("INSERT INTO pro_unitinfo(id, name, unitTypeId, outside_code, delState,areaId)" +
            "values (#{id},#{name},#{unitTypeId},#{outside_code},1,#{areaId})")
    int addUnitInfo(ProUnitInfo info);  //添加单位

    @Select("select count(*) from pro_unitinfo where outside_code = #{outside_code}")
    int isRepeat(ProUnitInfo unitInfo); //外部编号是否重复

    @Update("UPDATE pro_unitinfo set delState=2 where outside_code in (${ids}) and areaId = #{areaId}")
    int deleteUnit(Map<String,Object> params);//批量删除单位

    // 获取单位信息
    @Select("select * from pro_unitinfo where delState = '1' and areaId = #{areaId} order by outside_code desc")
    public List<ProUnitInfo> getUnitList(@Param("areaId") String areaId);

    // 查询单位信息
    @SelectProvider(type = UnitInfoDynSqlProvider.class, method = "getInfo")
    List<ProUnitInfo> getInfo(Map<String, Object> params);

}
